fix: Now getRelatedContactRelationships handle null arg#2982
Conversation
As we can remove fields now, relatedContact can be empty
WalkthroughThe 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/helpers.js`:
- Around line 213-214: The helper early-return currently returns an empty object
when relatedContact is falsy, which omits the related key and lets
oldContactCleaned?.relationships.related persist; update the early-return in the
helper (the branch that checks relatedContact) to return an object that
explicitly clears relationships.related (e.g., return { related: [] }) so
formValuesToContact correctly replaces prior related entries when calling
formValuesToContact/merging with oldContactCleaned.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 06d3c373-40bb-4574-ba49-97a520776a97
📒 Files selected for processing (1)
packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/helpers.js
| if (!relatedContact) return {} | ||
|
|
There was a problem hiding this comment.
Returning {} here can keep stale relationships.related
On Line 213, returning {} when relatedContact is null/falsy means no related key is produced. In formValuesToContact (packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/formValuesToContact.js:38-52), that allows previously merged oldContactCleaned?.relationships.related to survive instead of being cleared.
Suggested fix
export const getRelatedContactRelationships = relatedContact => {
- if (!relatedContact) return {}
+ if (!relatedContact) return { related: { data: [] } }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if (!relatedContact) return {} | |
| export const getRelatedContactRelationships = relatedContact => { | |
| if (!relatedContact) return { related: { data: [] } } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/cozy-ui-plus/src/Contacts/AddModal/ContactForm/helpers.js` around
lines 213 - 214, The helper early-return currently returns an empty object when
relatedContact is falsy, which omits the related key and lets
oldContactCleaned?.relationships.related persist; update the early-return in the
helper (the branch that checks relatedContact) to return an object that
explicitly clears relationships.related (e.g., return { related: [] }) so
formValuesToContact correctly replaces prior related entries when calling
formValuesToContact/merging with oldContactCleaned.
As we can remove fields now, relatedContact can be empty
Summary by CodeRabbit